/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.di;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import org.apache.log4j.PropertyConfigurator;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

/**
 *
 * @author DK
 */
public class ESService {

    public static String HOST;
    public static int PORT;
    public static String CLUSTER_NAME;
    public static String DIHOME = "D:\\elasticsearch";
    public static ESServiceConfig CONF;
   
    public ESService() {        
        CONF = new ESServiceConfig(ESService.DIHOME+"/config/elasticsearch.yml");
        System.setProperty("log4j.configuration", ESService.DIHOME + "/config/logging.yml");
        System.setProperty("path.logs", ESService.CONF.getProperty("path.logs"));
        PropertyConfigurator.configure(ESService.DIHOME + "/config/logging.yml");        
        ESService.HOST = ESService.CONF.getProperty("network.host");
        ESService.PORT = Integer.parseInt(ESService.CONF.getProperty("transport.tcp.port"));
        ESService.CLUSTER_NAME = ESService.CONF.getProperty("cluster.name");
    }
    
    public static TransportClient openTransportClient() {
        return new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", ESService.CLUSTER_NAME)).addTransportAddress(new InetSocketTransportAddress(ESService.HOST, ESService.PORT));
    }
}
